package com.inspur.edp.ai.flow.node;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.inspur.edp.ai.flow.metadata.AbsNode;
import com.inspur.edp.ai.flow.metadata.Edge;
import com.inspur.edp.ai.flow.metadata.serializer.NodesJsonDeserializer;
import com.inspur.edp.ai.flow.spi.GetSubFlowNode;
import com.inspur.edp.common.expr.ExprJsonDeserializer;
import com.inspur.edp.common.expr.Express;
import com.inspur.edp.common.expr.evaluator.ExpressEvaluator;
import com.inspur.edp.common.type.TypeRefer;
import lombok.Data;

import java.util.List;

/**
 * @author lizhaorui
 * @date 2025/8/15
 * @description
 */

@Data
public class LoopNode extends AbsNode implements GetSubFlowNode {

    public static final String KIND = "loop";

    public static final String ITEM_INDEX_KEY = "index";

    public LoopNode() {
        this.setKind(KIND);
    }

    /**
     * iterable -> 迭代器
     */
    private String loopType;

    /**
     * 迭代器表达式
     */
    @JsonDeserialize(using = ExprJsonDeserializer.class)
    private Express iterableExpr;

    /**
     * 迭代器表达式类型
     */
    private TypeRefer iterableExprType;

    /**
     * 迭代器计算表达式
     */
    @JsonIgnore
    private ExpressEvaluator iterableExprEvaluator;

    /**
     * 迭代器变量
     */
    private String iterableVariable;

    /**
     * body节点列表
     */
    @JsonDeserialize(using = NodesJsonDeserializer.class)
    private List<AbsNode> nodes;

    /**
     * body节点连线列表
     */
    private List<Edge> edges;


    @JsonIgnore
    public List<AbsNode> getSubFlowNodes() {
        return this.nodes;
    }

}